using AnhAnh;
using AutoSales;
using Facebook;
using FacebookLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;

public sealed class FormHistory : Form
{
	private BindingSource bindingSource_0 = new BindingSource();

	private IContainer icontainer_0;

	private Button buttonExport;

	private DataGridView dataGridView1;

	private Button buttonGetInteractive;

	private DateTimePicker dateTimePicker2;

	private DateTimePicker dateTimePicker1;

	private Button buttonFilter;

	private Label label1;

	private Label label2;

	public FormHistory()
	{
		this.InitializeComponent();
	}

	private void buttonExport_Click(object sender, EventArgs e)
	{
		if (this.dataGridView1.Rows.Count == 0)
		{
			return;
		}
		string str = string.Concat(Anh.CreateAppFolderData("Report"), "\\DetailReport.html");
		StreamWriter streamWriter = new StreamWriter(str, false, Encoding.UTF8);
		streamWriter.Write(FormMain.mAnh.DataGridToHTML(this.dataGridView1).ToString());
		streamWriter.Close();
		Process.Start(str);
	}

	private void buttonFilter_Click(object sender, EventArgs e)
	{
		this.method_2();
		this.method_0();
	}

	private void buttonGetInteractive_Click(object sender, EventArgs e)
	{
		if (this.dataGridView1.Rows.Count == 0)
		{
			return;
		}
		if (string.IsNullOrEmpty(FormMain.mToken))
		{
			UI.ShowMessage("You must login to see posts interactive", UI.MessageType.Error);
			return;
		}
		this.Cursor = Cursors.WaitCursor;
		Application.DoEvents();
		if (this.buttonGetInteractive.Text != "Get Interactive")
		{
			this.buttonGetInteractive.Text = "Get Interactive";
		}
		else
		{
			this.buttonGetInteractive.Text = "Stop";
		}
		FacebookClient facebookClient = new FacebookClient(FormMain.mToken);
		foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
		{
			Application.DoEvents();
			if (this.buttonGetInteractive.Text != "Stop")
			{
				break;
			}
			string str = row.Cells["PostId"].Value.ToString();
			int count = FormMain.mCoca.GetLikes(facebookClient, str, 25).Count;
			int num = FormMain.mCoca.GetComments(facebookClient, str, 25).Count;
			if (count > 25)
			{
				row.Cells["Like"].Value = "> 25";
			}
			else
			{
				row.Cells["Like"].Value = count;
			}
			if (num > 25)
			{
				row.Cells["Comment"].Value = "> 25";
			}
			else
			{
				row.Cells["Comment"].Value = num;
			}
		}
		this.buttonGetInteractive.Text = "Get Interactive";
		this.Cursor = Cursors.Default;
		Application.DoEvents();
	}

	private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex < 0)
		{
			return;
		}
		History dataBoundItem = this.dataGridView1.Rows[e.RowIndex].DataBoundItem as History;
		if (e.ColumnIndex == this.dataGridView1.Columns["Link"].Index)
		{
			Process.Start(string.Concat("https://www.facebook.com/", dataBoundItem.PostId));
		}
	}

	protected override void Dispose(bool bool_0)
	{
		if (bool_0 && this.icontainer_0 != null)
		{
			this.icontainer_0.Dispose();
		}
		base.Dispose(bool_0);
	}

	private void FormHistory_Shown(object sender, EventArgs e)
	{
		this.Cursor = Cursors.WaitCursor;
		Application.DoEvents();
		this.dateTimePicker1.Value = DateTime.Now.AddDays(-1);
		this.dateTimePicker2.Value = DateTime.Now;
		this.method_2();
		this.dataGridView1.DataSource = this.bindingSource_0;
		this.method_0();
		this.Cursor = Cursors.Default;
		Application.DoEvents();
	}

	private void InitializeComponent()
	{
		DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
		ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FormHistory));
		this.buttonExport = new Button();
		this.dataGridView1 = new DataGridView();
		this.buttonGetInteractive = new Button();
		this.dateTimePicker2 = new DateTimePicker();
		this.dateTimePicker1 = new DateTimePicker();
		this.buttonFilter = new Button();
		this.label1 = new Label();
		this.label2 = new Label();
		((ISupportInitialize)this.dataGridView1).BeginInit();
		base.SuspendLayout();
		this.buttonExport.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
		this.buttonExport.Location = new Point(697, 329);
		this.buttonExport.Name = "buttonExport";
		this.buttonExport.Size = new System.Drawing.Size(75, 25);
		this.buttonExport.TabIndex = 3;
		this.buttonExport.Text = "Export";
		this.buttonExport.UseVisualStyleBackColor = true;
		this.buttonExport.Click += new EventHandler(this.buttonExport_Click);
		this.dataGridView1.AllowUserToAddRows = false;
		this.dataGridView1.AllowUserToDeleteRows = false;
		this.dataGridView1.AllowUserToResizeRows = false;
		this.dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
		this.dataGridView1.BackgroundColor = SystemColors.Menu;
		this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
		this.dataGridView1.ColumnHeadersHeight = 30;
		this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
		dataGridViewCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle.BackColor = Color.Bisque;
		dataGridViewCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
		dataGridViewCellStyle.ForeColor = SystemColors.ControlText;
		dataGridViewCellStyle.SelectionBackColor = SystemColors.Highlight;
		dataGridViewCellStyle.SelectionForeColor = SystemColors.HighlightText;
		dataGridViewCellStyle.WrapMode = DataGridViewTriState.False;
		this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle;
		this.dataGridView1.Location = new Point(12, 12);
		this.dataGridView1.Name = "dataGridView1";
		this.dataGridView1.ReadOnly = true;
		this.dataGridView1.RowHeadersVisible = false;
		this.dataGridView1.RowTemplate.Height = 35;
		this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
		this.dataGridView1.Size = new System.Drawing.Size(760, 311);
		this.dataGridView1.TabIndex = 0;
		this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick);
		this.buttonGetInteractive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
		this.buttonGetInteractive.Location = new Point(589, 329);
		this.buttonGetInteractive.Name = "buttonGetInteractive";
		this.buttonGetInteractive.Size = new System.Drawing.Size(102, 25);
		this.buttonGetInteractive.TabIndex = 2;
		this.buttonGetInteractive.Text = "Get Interactive";
		this.buttonGetInteractive.UseVisualStyleBackColor = true;
		this.buttonGetInteractive.Click += new EventHandler(this.buttonGetInteractive_Click);
		this.dateTimePicker2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
		this.dateTimePicker2.Format = DateTimePickerFormat.Short;
		this.dateTimePicker2.Location = new Point(178, 331);
		this.dateTimePicker2.Name = "dateTimePicker2";
		this.dateTimePicker2.Size = new System.Drawing.Size(100, 20);
		this.dateTimePicker2.TabIndex = 15;
		this.dateTimePicker1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
		this.dateTimePicker1.Format = DateTimePickerFormat.Short;
		this.dateTimePicker1.Location = new Point(45, 331);
		this.dateTimePicker1.Name = "dateTimePicker1";
		this.dateTimePicker1.Size = new System.Drawing.Size(100, 20);
		this.dateTimePicker1.TabIndex = 14;
		this.buttonFilter.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
		this.buttonFilter.Location = new Point(284, 329);
		this.buttonFilter.Name = "buttonFilter";
		this.buttonFilter.Size = new System.Drawing.Size(75, 25);
		this.buttonFilter.TabIndex = 16;
		this.buttonFilter.Text = "Filter";
		this.buttonFilter.UseVisualStyleBackColor = true;
		this.buttonFilter.Click += new EventHandler(this.buttonFilter_Click);
		this.label1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
		this.label1.AutoSize = true;
		this.label1.Location = new Point(12, 334);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(30, 13);
		this.label1.TabIndex = 17;
		this.label1.Text = "From";
		this.label2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
		this.label2.AutoSize = true;
		this.label2.Location = new Point(152, 334);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(20, 13);
		this.label2.TabIndex = 18;
		this.label2.Text = "To";
		base.AutoScaleDimensions = new SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(784, 362);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.label1);
		base.Controls.Add(this.buttonFilter);
		base.Controls.Add(this.dateTimePicker2);
		base.Controls.Add(this.dateTimePicker1);
		base.Controls.Add(this.buttonGetInteractive);
		base.Controls.Add(this.dataGridView1);
		base.Controls.Add(this.buttonExport);
		base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
		base.Name = "FormHistory";
		base.StartPosition = FormStartPosition.CenterParent;
		this.Text = "History";
		base.Shown += new EventHandler(this.FormHistory_Shown);
		((ISupportInitialize)this.dataGridView1).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	private void method_0()
	{
		this.dataGridView1.Columns["Id"].Width = 35;
		this.dataGridView1.Columns["CreatedTime"].Width = 110;
		this.dataGridView1.Columns["Category"].Width = 210;
		this.dataGridView1.Columns["Facebook"].Width = 205;
		this.dataGridView1.Columns["PostId"].Visible = false;
		if (!this.dataGridView1.Columns.Contains("Link"))
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn()
			{
				Name = "Link",
				HeaderText = "Link",
				Width = 60
			};
			dataGridViewTextBoxColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
			this.dataGridView1.Columns.Add(dataGridViewTextBoxColumn);
		}
		if (!this.dataGridView1.Columns.Contains("Like"))
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn()
			{
				Name = "Like",
				HeaderText = "Like",
				Width = 60
			};
			dataGridViewTextBoxColumn1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
			this.dataGridView1.Columns.Add(dataGridViewTextBoxColumn1);
		}
		if (!this.dataGridView1.Columns.Contains("Comment"))
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn()
			{
				Name = "Comment",
				HeaderText = "Comment",
				Width = 60
			};
			dataGridViewTextBoxColumn2.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
			this.dataGridView1.Columns.Add(dataGridViewTextBoxColumn2);
		}
		foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
		{
			DataGridViewLinkCell dataGridViewLinkCell = new DataGridViewLinkCell()
			{
				Value = string.Concat("https://www.facebook.com/", row.Cells["PostId"].Value)
			};
			row.Cells["Link"] = dataGridViewLinkCell;
		}
	}

	private void method_1(object sender, EventArgs e)
	{
	}

	private void method_2()
	{
		FormHistory.Class2 class2 = new FormHistory.Class2();
		AutoSalesContext autoSalesContext = new AutoSalesContext();
		class2.dateTime_0 = this.dateTimePicker1.Value.Date;
		DateTime dateTime = this.dateTimePicker2.Value.Date.AddDays(1);
		class2.dateTime_1 = dateTime.AddTicks((long)-1);
		BindingSource bindingSource0 = this.bindingSource_0;
		DbSet<History> historys = autoSalesContext.Histories;
		ParameterExpression parameterExpression = Expression.Parameter(typeof(History), "m");
		BinaryExpression binaryExpression = Expression.AndAlso(Expression.GreaterThanOrEqual(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(History).GetMethod("get_CreatedTime").MethodHandle)), Expression.Field(Expression.Constant(class2), FieldInfo.GetFieldFromHandle(typeof(FormHistory.Class2).GetField("dateTime_0").FieldHandle)), false, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(DateTime).GetMethod("op_GreaterThanOrEqual", new Type[] { typeof(DateTime), typeof(DateTime) }).MethodHandle)), Expression.LessThanOrEqual(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(History).GetMethod("get_CreatedTime").MethodHandle)), Expression.Field(Expression.Constant(class2), FieldInfo.GetFieldFromHandle(typeof(FormHistory.Class2).GetField("dateTime_1").FieldHandle)), false, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(DateTime).GetMethod("op_LessThanOrEqual", new Type[] { typeof(DateTime), typeof(DateTime) }).MethodHandle)));
		ParameterExpression[] parameterExpressionArray = new ParameterExpression[] { parameterExpression };
		IQueryable<History> histories = historys.Where<History>(Expression.Lambda<Func<History, bool>>(binaryExpression, parameterExpressionArray));
		ParameterExpression parameterExpression1 = Expression.Parameter(typeof(History), "m");
		MemberExpression memberExpression = Expression.Property(parameterExpression1, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(History).GetMethod("get_Id").MethodHandle));
		ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[] { parameterExpression1 };
		bindingSource0.DataSource = histories.OrderByDescending<History, int>(Expression.Lambda<Func<History, int>>(memberExpression, parameterExpressionArray1)).ToList<History>();
	}

	private sealed class Class2
	{
		public DateTime dateTime_0;

		public DateTime dateTime_1;

		public Class2()
		{
		}
	}
}